﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec
{
    public partial class NewTVNN : System.Web.UI.Page
    {
        public int trang { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["page"] != null)
            {
                trang = int.Parse(Request.QueryString["page"]);
            }
            else
            {
                trang = 1;
            }
            if (!IsPostBack)
            {
                LoadData("TVNN");

            }
        }
        public void LoadData(string phanLoai)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            int page = 1;
            if (Request.QueryString["page"] != null)
            {
                page = int.Parse(Request.QueryString["page"]);
            }
            rptTin.DataSource = BLL.ArticleHelper.List_BV_Valueconfig(phanLoai, page, 7);
            rptTin.DataBind();
            int Count = BLL.ArticleHelper.Count_Article_value_config(phanLoai);
            int TotalPage = Count / 7 + 1;
            if (Count < 1)
            {
                lbtPreview.Visible = false;
                lbtNext.Visible = false;
            }
            if (page == 1)
            {
                lbtPreview.Visible = false;
            }
            if (page == TotalPage)
            {
                lbtNext.Visible = false;
            }
            for (int i = page - 4; i < page + 4; i++)
            {
                if (i < 1)
                    continue;
                if (i > TotalPage)
                    continue;
                if (Count > 0)
                {
                    if (i == page)
                        ltlPaging.Text += "<li><a class='current' href='" + path + "?page=" + i + "'>" + i + "</a></li>";
                    else
                        ltlPaging.Text += "<li><a href='" + path + "?page=" + i + "'>" + i + "</a></li>";
                }
            }
        }
        protected void lbtPreview_Click(object sender, EventArgs e)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            Response.Redirect(path + "?page=" + (trang - 1));
        }

        protected void lbtNext_Click(object sender, EventArgs e)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            Response.Redirect(path + "?page=" + (trang + 1));
        }
    }
}